home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / wanderer / read.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-26  |  1.1 KB  |  60 lines

  1. #include "wand_head.h"
  2.  
  3. extern int edit_mode;
  4. extern char screen[NOOFROWS][ROWLEN+1];
  5.  
  6. int rscreen(num,maxmoves)
  7. int *maxmoves, num;
  8. {
  9. int  y;
  10. FILE *fp;
  11. char name[50];
  12. char (*row_ptr)[ROWLEN+1] = screen;
  13. if(!edit_mode)
  14.     sprintf(name,"%s/screen.%d",SCREENPATH,num);
  15. else
  16.     sprintf(name,"./screen");
  17. fp = fopen(name,"r");
  18. if(fp == NULL)
  19.     printf("\nFile for screen %d unavailable.\n\n",num) ;
  20. else
  21.     {
  22.     for(y = 0;y<NOOFROWS;y++)
  23.         {
  24.         fgets((*row_ptr++),ROWLEN + 1,fp);
  25.     fgetc(fp);                         /* remove newline char*/
  26.     };
  27.     if(fscanf(fp,"%*s\n%d",maxmoves) != 1)
  28.     *maxmoves=0;
  29.     fclose(fp);
  30.     };
  31. return (fp == NULL);
  32. }
  33.  
  34. int wscreen(num,maxmoves)
  35. int maxmoves, num;
  36. {
  37. int  y,x;
  38. FILE *fp;
  39. char (*row_ptr)[ROWLEN+1] = screen;
  40. fp = fopen("./screen","w");
  41. if(fp == NULL)
  42.     printf("\nFile for screen cannot be written.\n\n") ;
  43. else
  44.     {
  45.     for(y = 0;y<NOOFROWS;y++)
  46.         {
  47.     for(x = 0;x<ROWLEN;x++)
  48.         fputc(row_ptr[y][x],fp);
  49.     fputc('\n',fp);
  50.     };
  51.     for(x = 0; x<ROWLEN;x++)
  52.     fputc('#',fp);
  53.     fputc('\n',fp);
  54.     if(maxmoves != 0)
  55.     fprintf(fp,"%d\n",maxmoves);
  56.     fclose(fp);
  57.     };
  58. return (fp == NULL);
  59. }
  60.